<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="kit-admin/plugins/layui/css/layui.css" media="all">
</head>

<body>

<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="query">查询</button>
    <#--<button class="layui-btn" data-type="add">新增维修日志</button>-->
    <#--<button class="layui-btn" data-type="edit">编辑维修日志</button>-->
</div>
<table class="layui-table" lay-data="{height:315, url:'repairLogController.do?dataGridTotalRepairType', page:true, height: 'full-60'}" lay-filter="repairLog" id="repairLog">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <#--<th lay-data="{field:'id', width:200, sort: true}">id</th>-->
        <th lay-data="{field:'name', width:200, sort: true,templet: '#name'}">维修类别</th>
        <#--<th lay-data="{field:'applyStaffDepartment', width:200, sort: true,templet: '#applyStaffDepartment'}">报修人部门</th>-->
        <#--<th lay-data="{field:'applyReason', width:200, sort: true}">报修内容</th>-->
        <#--<th lay-data="{field:'solveWay', width:200, sort: true}">解决方法</th>-->
        <#--<th lay-data="{field:'repairStaffName', width:200, sort: true}">维修人姓名</th>-->
        <#--<th lay-data="{field:'repairType', width:200, sort: true}">维修类别</th>-->
        <#--<th lay-data="{field:'costMoney', width:200, sort: true}">损失金额</th>-->
        <#--<th lay-data="{field:'applyTime', width:200, sort: true}">报修时间</th>-->
        <th lay-data="{field:'count', width:200, sort: true}">总计</th>
    </tr>
    </thead>
</table>
<#include "/common/array2json.ftl"/>
<script type="text/html" id="name">
    {{#  if(d.name == 1) { }}
    <span class="layui-badge layui-bg-green">{{  '硬件问题' }}</span>
    <#--<span class="layui-badge layui-bg-blue">人未到</span>-->
    {{#  } else if(d.name == 2) { }}
    <span class="layui-badge">信息安全</span>
    {{#  } else if(d.name == 3) { }}
    <span class="layui-badge layui-bg-green">信息系统</span>
    {{#  } else if(d.name == 4) { }}
    <span class="layui-badge layui-bg-green">应用系统</span>
    {{#  } else if(d.name == 5) { }}
    <span class="layui-badge layui-bg-green">人员培训</span>
    {{#  } else { }}
    <span style="color: red;">未知状态</span>
    {{#  } }}
</script>

<script src="kit-admin/plugins/layui/layui.js"></script>
<script>
    layui.use('table', function() {
        var table = layui.table;
        var paramCache={};
        var $ = layui.$, active = {
            query: function(){ //添加数据
                /* var checkStatus = table.checkStatus('idTest')
                ,data = checkStatus.data;
                layer.alert(JSON.stringify(data)); */
                var ml=layer.open({
                    type: 2,
                    title: false,
                    area: ['630px', '360px'],
                    btn: ['确定','重置' ,'取消'], //只是为了演示
                    shade: 0.8,
                    closeBtn: 1,
                    shadeClose: true,
                    content: 'repairLogController.do?goCommonDateQuery'+param2url(paramCache),
                    yes: function(index,lay){
                        var body = layer.getChildFrame('body', index);
                        var formArr = body.find("form").serializeArray();
                        var param=arr2json(formArr);
                        paramCache=param;
//                        layer.msg("添加成功");
                        table.reload('repairLog',{
                            page: {
                                curr: 1 //重新从第 1 页开始
                            },
                            where:param,
                        });
                        layer.close(index);
                    },
                    btn2: function(index, layero){
                        for(key in paramCache){
                            paramCache[key]="";
                        }
                        table.reload('repairLog',{
                            page: {
                                curr: 1 //重新从第 1 页开始
                            },
                            where:paramCache,
                        });
                    },
                });
                layer.full(ml);
            },
            add: function(){ //添加数据
                /* var checkStatus = table.checkStatus('idTest')
                ,data = checkStatus.data;
                layer.alert(JSON.stringify(data)); */
                var ml=layer.open({
                    type: 2,
                    title: false,
                    area: ['630px', '360px'],
                    btn: ['确定', '取消'], //只是为了演示
                    shade: 0.8,
                    closeBtn: 1,
                    shadeClose: true,
                    content: 'repairLogController.do?goRepairLogAdd',
                    yes: function(index,lay){
                        var body = layer.getChildFrame('body', index);
                        var formArr = body.find("form").serializeArray();
                        var param=arr2json(formArr);
                        post("repairLogController.do?doRepairLogAdd",param,data=>{
                            layer.msg("添加成功");
                        table.reload('repairLog',{
                            page: {
                                curr: 1 //重新从第 1 页开始
                            },
                        });
                    });
                        layer.close(index);

                    }
                });
                layer.full(ml);
            },
            edit: function(){
                var checkStatus = table.checkStatus('repairLog')
                        ,data = checkStatus.data;
                if(1!=data.length){
                    layer.msg("请选择一行数据");
                    return;
                }
                data=data[0];
                var ml=layer.open({
                    type: 2,
                    title: false,
                    area: ['630px', '360px'],
                    btn: ['确定', '取消'], //只是为了演示
                    shade: 0.8,
                    closeBtn: 1,
                    shadeClose: true,
                    content: 'repairLogController.do?goRepairLogUpdate&id='+data.id,
                    yes: function(index,lay){
                        var body = layer.getChildFrame('body', index);
                        var formArr = body.find("form").serializeArray();
                        var param=arr2json(formArr);
                        post("repairLogController.do?doRepairLogUpdate",param,data=>{
                            layer.msg("更新成功");
                        $("button.layui-laypage-btn").click();
                    });
                        layer.close(index);
                    }
                });
                layer.full(ml);
            }
        };
    <#include "/common/post.js"/>

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>

</html>